<template>
  <div>
    <el-table :data="userlist" height="250" border style="width: 100%">
      <el-table-column prop="uid" label="用户编号" width="180"></el-table-column>
      <el-table-column prop="username" label="用户名称" width="180"></el-table-column>
      <el-table-column prop="rolename" label="所属角色" width="180"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="item">
          <div>
            <span v-if="item.row.status ==1">启用</span>
            <span v-else>禁用</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button type="primary" size="mini" @click="edit(item.row.uid)">编辑</el-button>
            <el-button type="danger" size="mini" @click="del(item.row.uid)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
        <!-- 分页 -->
    <el-pagination :page-size='2' background layout="prev, pager, next" :total="count" @current-change='changePage'></el-pagination>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { userdelete } from "../../request/api.js";
export default {
  data() {
    return {
    };
  },
  computed: {
    ...mapGetters({
      userlist: "manger/getUser",
      count:'manger/getCount'
    })
  },
  methods: {
    edit(uid) {
      this.$emit("edit",uid);     
    },
    ...mapActions({
      getManger: "manger/getMangerActions",
      getCount:'manger/getCountActions',
      changePageActions:'manger/changePageActions'
    }),
    //页面切换
    changePage(n){
      this.changePageActions(n)
    },
    //删除：
    del(uid) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          userdelete({uid})
          .then(res=>{
            if(res.code==200){
              this.$message.success(res.msg)
              this.getManger()
              //调用总条数
              this.getCount()
            }else{
              this.$message.error(res.msg)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },
  mounted() {
    this.getManger();
    this.getCount()
  }
};
</script>

<style  scoped>
</style>
